﻿//===================================================================
// 项目名称  
// 模块名称：配送管理
// 类    名：
//===================================================================
// 历史：
// Date        Modified_By  Reason      Description 
// 2009/11/02    刘亮        创建         废烟支管理

//===================================================================
//  Copyright (c) 2009-2010   
//===================================================================

var form1 = {
    type  : "form", 
    name  : "search",   
    title : "查询条件",
    
    isSearch : true,            
    items : [
            
           
            {
                type:"calendar",
                title:"开始日期",
                // url:"../data/MoistureOvenCheckView5.txt" ,
                root:"dataset.simplecombobox"
            },
			 {
                type:"calendar",
                title:"结束日期",
                // url:"../data/MoistureOvenCheckView5.txt" ,
                root:"dataset.simplecombobox"
            },
			{ 
                type:"combox",
                title:"下级分销商或门店",                                         
                url:"data/dangwei.txt",
                root:"dataset.simplecombobox"                
            } ,
			{ 
                type:"combox",
                title:"资金形式",                                         
                url:"data/zijingxinshi.txt",
                root:"dataset.simplecombobox"                
            } 
    ],

   layoutConfig : 
    {
        columns : 4
    },
    layout : 
	[
		{
		items:
			[
				{'name':'开始日期'}, 
				{'name':'结束日期'}, 
				{'name':'下级分销商或门店'},
				{'name':'资金形式'}  
			]
		}
    ]
};

//=======================================================================================
//定义一个静态列表表单对象 grid1
//=======================================================================================
var grid1 = {
    "name"      : "grid1",
    "type"      : "grid",
    "title"     : "配送管理",
    colCheckbox : true,
    pageSize:4,
    //"url"       : "data/peisong1.txt",

    "tbar"      : [
        {text: '新增'}, '-',
        {text: '删除'}
    ],
    "bindRelation"   : {
        "root"  :"dataset.billVo",
         id    : "id",
        "col"   :[  
{"header": "隐藏事务主键","width": 0,"dataIndex": "transactionId",hidden:true},  
            {"header":"配送日期",  "width":100, "align":"left",  "dataIndex":"billDate"},    
            {"header":"下级分销商或门店",  "width":100, "align":"left","dataIndex":"otherDic2Name"},
            {"header":"资金形式",  "width":100, "align":"left","dataIndex":"otherDic1Name"},     
            {"header":"经手人",    "width":100, "align":"left",  "dataIndex":"operator"},     
            {"header":"备注",      "width":100, "align":"left",  "dataIndex":"remark"},
            {"header":"修改",      "actionCol" :true },    
            {"header":"查看",      "actionCol" :true }
        ]
        
    }
};
var grid2 = {
    "name"      : "grid2",
    "type"      : "grid",
    "title"     : "配送明细",
   // "url"       : "data/peisong2.txt",
    haveCheckCol: true,
       "bindRelation"   : {
        "root"  :"dataset.billDetailVo",
        id   : "id",
        "col"   :[     
            {"header":"产品名称",  "width":100, "align":"left",  "dataIndex":"materielName"},      
            {"header":"型号规格",  "width":100, "align":"left"},
            {"header":"供给形式",  "width":100, "align":"left","dataIndex":"otherDic1Name"},
            {"header":"单价",      "width":100, "align":"left","dataIndex":"price"},
            {"header":"数量",      "width":100, "align":"left",  "dataIndex":"amount"},
            {"header":"金额",      "width":100, "align":"left","dataIndex":"money"}
        ]
        
    }
};

var page1 = new Sail.page({
    id : "page_001",
    haveNavi:true,
        localNaviText : "您的位置：仓库管理>配送管理",
    frames : {
        name   : "RollStandardList",
        title  : "标题",
        autoLoad : false,
        items  : [form1,grid1,grid2],
        layoutConfig: {
            columns: 2,
            width: [0.5, 0.5]
        },
        layout: [
        {
            items: [{
                name: 'search',
                colspan:2
            }]
        },
        {
            items: [
            {
                name: 'grid1'
            },
            {
                name: 'grid2'
            }]
        }       
        
        ],
      
        bindEvent2Items : function(){
            

            $('grid1').getButton('新增').on('click',function(){
                 Sail.open("peisongUpdate.html","add",{},800,600);
            });
            
             $('grid1').addAction('修改',function(pid,row,record,value){
                 var flag = Sail.open("peisongUpdate.html","update",{"id":pid},1000,800);
                 flag && queryData();
             });           
      
             $('grid1').getButton('删除').on('click',function(){
               if (confirm("确认要删除所选择的数据吗？")) {
                   var ids = $('grid1').getSelections('id').join(':');
                   alert(ids);
                   if (ids==''){
                     return;
                   }
                   Sail.postData('../../distribution.do?method=delete', {
                       'ids': ids
                   },
                   function(flag, getData) {
                       if (flag == "true") {
                           Ext.Msg.alert("提示", "操作成功!");
                           $('grid1').load();
                       } else {
                           Ext.Msg.alert("警告", getData.dataset.response.content);
                       }
                   });
               }
           });
             
         $('grid1').on('afterload', function () {
             $('grid1').selectFirstRow();
             var id = $('grid1').getSelections('id');
             if (id == "") {
                 $('grid2').removeAll();
             }
         });
         $('grid1').on('rowclick', function (id, row, record) {
        	
        	 if (id == "") {
     			return;
     		}
        	 var transactionId=record.get("transactionId");
     		if (transactionId == "") {
     			return;
     		}
             $('grid2').load("../../distribution.do?method=listDetail&transactionId="+transactionId);
         });

        }       
     },
     afterRun : function(){
         queryData();
     }
 });

page1.run();

function queryData() {
	$('grid1').load("../../distribution.do?method=list&filter_EQS_sysFlag=1");
}

    